home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Libraries / Framework / Includes / UMacAppGlobals.h < prev    next >
Encoding:
Text File  |  1996-04-03  |  13.5 KB  |  377 lines  |  [TEXT/MPS ]

  1. // UMacAppGlobals.h
  2. // Copyright © 1984-96 by Apple Computer, Inc. All rights reserved.
  3.  
  4. #ifndef __UMACAPPGLOBALS__
  5. #define __UMACAPPGLOBALS__
  6.  
  7. // MacApp
  8.  
  9. #ifndef __MACAPPTYPES__
  10. #include "MacAppTypes.h"
  11. #endif
  12.  
  13. #ifndef __UCLASSDESC__
  14. #include "UClassDesc.h"
  15. #endif
  16.  
  17. #ifndef __UCOREGLOBALS__
  18. #include "UCoreGlobals.h"
  19. #endif
  20.  
  21. #ifndef __UERRORMGR__
  22. #include "UErrorMgr.h"
  23. #endif
  24.  
  25. #ifndef __UFAILURE__
  26. #include "UFailure.h"
  27. #endif
  28.  
  29. // Toolbox
  30.  
  31. #ifndef __APPLEEVENTS__
  32. #include <AppleEvents.h>
  33. #endif
  34.  
  35. #ifndef __NOTIFICATION__
  36. #include <Notification.h>
  37. #endif
  38.  
  39. #ifndef __PROCESSES__
  40. #include <Processes.h>
  41. #endif
  42.  
  43. // For ExitToShell
  44. #ifndef __SEGLOAD__
  45. #include <SegLoad.h>
  46. #endif
  47.  
  48. #ifndef __STANDARDFILE__
  49. #include <StandardFile.h>
  50. #endif
  51.  
  52. // ANSI
  53.  
  54. #ifndef __LIMITS__
  55. #include <limits.h>
  56. #endif
  57.  
  58. //----------------------------------------------------------------------------------------
  59. // Forward and external class declarations. 
  60. //----------------------------------------------------------------------------------------
  61.  
  62. class TObject;
  63. class TPrintHandler;
  64. class TView;
  65.  
  66. //----------------------------------------------------------------------------------------
  67. // Global variable declarations
  68. //----------------------------------------------------------------------------------------
  69.  
  70. extern TextStyle gSystemStyle;
  71.     // System's default text style
  72.  
  73. extern TextStyle gApplicationStyle;
  74.     // Application's default text style
  75.  
  76. extern TextStyle gApplicationStyle9;
  77.     // Application's default text style, 9 Point
  78.  
  79. extern WindowRef gWorkPort;
  80.     // Pointer to a window that is created during initialization, but never shown or
  81.     // enumerated.
  82.  
  83. extern RgnHandle gTemporaryRegion;
  84.     // gTemporaryRegion is a temporary RgnHandle created in InitUMacApp. When debugging: before
  85.     // using gTemporaryRegion, call UseTemporaryRegion and when done call DoneWithTemporaryRegion; this ensures
  86.     // that 2 routines do not try to use gTemporaryRegion and the same time
  87.  
  88. extern NMRecPtr gNotificationPtr;
  89.     // Passed to all occurrences of AEInteractWithUser.  Initialized to NULL so the
  90.     // AppleEvent manager will provide default notification behavior.  Point it at
  91.     // your own custom notification record if you want other behavior
  92.     
  93. extern ModalFilterYDProcPtr gModalFilterYDProcPtr;
  94.     // Default returnval for SFPut/GetParms.  Initialized to MacAppStandardFileFilter.
  95.     
  96. #if qDebug
  97. extern Boolean gBusyTemporaryRegion;
  98.     // Is gTemporaryRegion in use?
  99.  
  100. extern CStr255 gUsedBy;
  101.     // The routine using gTemporaryRegion
  102. #endif
  103.  
  104. //----------------------------------------------------------------------------------------
  105. // Manage a temporary region
  106. //----------------------------------------------------------------------------------------
  107. class CTemporaryRegion
  108. {
  109. protected:
  110.     static RgnHandle    fCachedRgn;                // the single level region cache
  111.     
  112.     FailInfo    fFailInfo;                        // the failure record that references
  113.                                                 // the failure handling method
  114.                                                 
  115.     RgnHandle    fRgnHandle;                        // the temp region
  116.  
  117. protected:
  118.     void* operator new(size_t size);            // prohibit "new CTemporaryRegion"
  119.     void operator delete(void* obj);            // avoid compiler warnings
  120.     
  121. public:
  122.     CTemporaryRegion();
  123.     // Allocates the fRgnHandle and installs the failure handler.
  124.  
  125.     ~CTemporaryRegion();
  126.     // Deallocates the fRgnHandle and removes the failure handler.
  127.  
  128.     void Cleanup();
  129.     
  130.     static void CallCleanup(void* context);
  131.     
  132.     //------------------------------------------------------------------------------------
  133.     // Conversion operator methods
  134.     //------------------------------------------------------------------------------------
  135.         
  136.     operator RgnHandle() { return fRgnHandle; }
  137.         // Conversion operator, for converting CTemporaryRegion to a RgnHandle.
  138. };
  139.  
  140. //----------------------------------------------------------------------------------------
  141. // These are really private, but they're here in case access is needed.
  142. //----------------------------------------------------------------------------------------
  143.  
  144. extern FailInfo pFi;                        // Outermost failure handler
  145.  
  146.  
  147. //----------------------------------------------------------------------------------------
  148. // Debugging
  149. //----------------------------------------------------------------------------------------
  150.  
  151. #if qDebug
  152. void DoneWithTemporaryRegion();
  153.     // Indicates that gTemporaryRegion is no longer in use. Call this only if qDebug is true.
  154.  
  155. void EnterDebugger(Boolean entering);
  156.     // Call to enter the MacApp Debugger
  157.  
  158. void UseTemporaryRegion(const CStr255& byWhom);
  159.     // Call this when you are about to use gTemporaryRegion and qDebug is true. Used with
  160.     // DoneWithTemporaryRegion will prevent you from trying to use gTemporaryRegion from two places at the
  161.     // same time.
  162.  
  163. #endif
  164.  
  165.  
  166. //----------------------------------------------------------------------------------------
  167. // Windows
  168. //----------------------------------------------------------------------------------------
  169.  
  170. Boolean ParseTitleTemplate(CStr255& itsTemplate,
  171.                            short& preDocname,
  172.                            short& constTitle);
  173.     // Used in TWindow::IWindow to parse the template for window titles. Returns true if it
  174.     // changed the template. preDocname is start of document name in CString; constChars is
  175.     // total # characters of window title that are constants. (These values are fixed
  176.     // regardless of the document name.) If preDocname is 0, then the entire title is
  177.     // constant.
  178.  
  179. Boolean SubstituteInTitle(CStr255& title,
  180.                           const CStr255& newStuff,
  181.                           short preDocname,
  182.                           short constTitle);
  183. // Substitutes newStuff into the template as parsed by ParseTitleTemplate; returns true if
  184. // a substitution was made.
  185.  
  186.  
  187. //----------------------------------------------------------------------------------------
  188. // Object Creation Utilities
  189. //----------------------------------------------------------------------------------------
  190.  
  191. void RegisterStdType(const CStr255& typeName, IDType signature);
  192.     // Associates the given class with a signature.
  193.  
  194. IDType GetStandardType(const ClassDesc* itsClassDesc);
  195.     // Return the signature for the given class.
  196.  
  197. const ClassDesc* GetClassDescFromSignature(IDType signature);
  198.     // Returns the class descriptor associated with a given signature, or NULL
  199.  
  200. const ClassDesc* DetermineClassDesc(IDType signature, const ClassName& className);
  201.     // Returns the ClassDesc associated with the given class name, if className is not
  202.     // empty. Returns the ClassDesc associated with the given signature, if className is
  203.     // empty
  204.  
  205. TObject* NewStdObject(IDType signature);
  206.     // Returns the prototype object for the given signature.
  207.  
  208. TObject* NewObjectBySignature(IDType signature,
  209.                               const ClassName& className);
  210.     // Returns an instance of class "className" if className is non-empty. Returns the
  211.     // prototype object for the given signature if className is empty
  212.  
  213.  
  214. //----------------------------------------------------------------------------------------
  215. // Initialization code that needs to always be compiled for 68000.
  216. //----------------------------------------------------------------------------------------
  217.  
  218. // void InitUMacApp(short callsToMoreMasters);
  219.     // Initialize the UMacApp unit.
  220.     // Call this in your program after calling InitToolBox and ValidateConfiguration.
  221. // InitUMacApp is now a macro. The code formerly contained in the InitUMacApp routine has 
  222. // been split into three parts: InitUMacApp_Step1, InstallFailureHandler, and 
  223. // InitUMacApp_Step3. The reason for splitting up InitUMacApp is that on PowerPC the outermost
  224. // failure handler must be set up in the main program so that the address saved by setjmp in Try
  225. // is part of the call chain. This code was moved into a macro called InstallFailureHandler.
  226. // InstallFailureHandler _MUST_ be called from main for PowerPC.
  227.  
  228. #define InitUMacApp(callsToMoreMasters)                        \
  229.     InitUMacApp_Step1();                                    \
  230.                                                             \
  231.     /* Install the permanent Outermost failure handler */    \
  232.     InstallFailureHandler;                                    \
  233.                                                             \
  234.     InitUMacApp_Step3(callsToMoreMasters);
  235.  
  236. #define InstallFailureHandler        \
  237.     pFi.Reset();        /* ensure that pFi is in an initial state */    \
  238.     Try(pFi)    \
  239.     { }            \
  240.     else {        \
  241.         if (pFi.error != noErr) {        /* check to see if an alert has already been displayed */    \
  242.             if (pFi.message == 0)                                                                    \
  243.                 pFi.message = messageInitializationFailed;    /* if no message specified, use our own */    \
  244.             ErrorAlert(pFi.error, pFi.message);                                                        \
  245.             }            \
  246.         ExitToShell();    \
  247.         }
  248.  
  249. void InitUMacApp_Step1();
  250. void InitUMacApp_Step3(short callsToMoreMasters);
  251.  
  252. //----------------------------------------------------------------------------------------
  253. // Miscellaneous
  254. //----------------------------------------------------------------------------------------
  255.  
  256. void DoAlertKeyDown(DialogRef theDialog, short itemNo);
  257.     // Given a dialog pointer and button item, simulate pressing the button
  258.  
  259. void DoInitUMacApp();
  260.     // Should be called only by InitUMacApp. It is here because this doesn't need to be
  261.     // universal code but InitUMacApp does.
  262.  
  263. void GetAlertButtonTitle(DialogRef theDialog, short itemNo, CStr255& theTitle);
  264.     // Given a dialog pointer and a button item, return the title of that button
  265.  
  266. Boolean CompareAlertKeysToItem(DialogRef theDialog, const CStr2& theChars, short& itemHit);
  267.     // Compares the multi-byte char to the first character of each button title
  268.     // 1st button in alert (by convention == "OK"). 2nd button in alert (by convention ==
  269.     // "Cancel"). 3rd button in alert (by convention == "No")
  270.  
  271. void DrawDefaultProc(DialogRef dlog);
  272.     // Used by the MinimalAlertFilter to draw the bold outline around the default button
  273.  
  274. pascal Boolean MinimalAlertFilter(DialogRef theDialog, EventRecord& theEvent, short& itemHit);
  275.     // MacApp's minimal alert filter; handles return & enter, command-. and escape, and
  276.     // draws the bold outline around the default button
  277.     // NOTE: Left with pascal keyword so it could continue to be used with the Toolbox
  278.     // Dialog Manager.
  279.     
  280. pascal Boolean MacAppAlertFilter(DialogRef theDialog,
  281.                                  EventRecord& theEvent,
  282.                                  short& itemHit);
  283.     // Default alert filter used throughout MacApp. Lets you answer yes and no to dialogs
  284.     // with keystrokes. Handles "command-." and escape. If the alert has not been called in a
  285.     // failure sequence then the application also handles update and activate events and
  286.     // idles.
  287.     // NOTE: Requires pascal keyword for use with the Toolbox Dialog Manager.
  288.  
  289. pascal Boolean MacAppAppleEventIdleProc(EventRecord& theEventRecord,
  290.                                         long& sleepTime,
  291.                                          RgnHandle& mouseRgn);
  292.     // Default AppleEvent idle proc used throughout MacApp. Handles update and activate events
  293.     // NOTE: Requires pascal keyword for use with the Apple Event Manager.
  294.  
  295. pascal Boolean MacAppStandardFileFilter(DialogRef theDialog, EventRecord* theEvent,
  296.                             short* itemHit, void *yourDataPtr);
  297.     // Default Filter proc for Standard File dialogs. Handles update and activate events
  298.     // NOTE: Requires pascal keyword for use with Standard File.
  299.  
  300. void ApplicationBeep();
  301.     // If gApplication is not NULL just calls gApplication->Beep else it does a SysBeep.
  302.     // Removes a circular reference for UFailure.
  303.  
  304. DialogRef GetNewCenteredDialog(ResNumber dialogID,
  305.                                Ptr dStorage,
  306.                                WindowRef behind);
  307.     // The same as GetNewDialog except it centers the dialog on the screen and sets the
  308.     // cursor to an arrow.
  309.  
  310. void GetTextStyleFontInfo(const TextStyle& theTextStyle,
  311.                           FontInfo& theFontInfo,
  312.                           short& theFontHeight);
  313.     // Returns the FontInfo record for the font/ face/ size specified in theTextStyle. Uses a
  314.     // temporary port so you don't have to. Also returns the font's line height.
  315.  
  316. void ExitMacApp();
  317.     // Call this if for some reason you want to immediately exit the application. It calls
  318.     // gApplication->Terminate, cleans up some other internal stuff, and then calls
  319.     // ExitToShell. (Normally, you would not call this, because MacApp takes care of
  320.     // terminating the application.)
  321.  
  322. void InstallIfPrintHandler(TPrintHandler* aPrintHandler, TView* aView);
  323.     // Install a clone of aPrintHandler into the view if aPrintHandler is not the same as
  324.     // the NULL print handler. (Typically if printing is initialized.) This lets us install
  325.     // a print handler if printing is being used in the application and do NOTHING if it
  326.     // is not.
  327.  
  328. RgnHandle MakeNewRgn();
  329.     // Calls NewRgn, then FailNIL
  330.  
  331. #ifdef __cplusplus
  332. extern "C" {
  333. #endif
  334. void CleanupMacApp (void);
  335.     // Installed as an atexit procedure.
  336. #ifdef __cplusplus
  337. }
  338. #endif
  339.  
  340. //==========================================================================================
  341. // The following routines are only supported for System 7
  342. //==========================================================================================
  343.  
  344. OSErr GetSysVolume(short& vRefNum);
  345.     // Get the vRefNum of the system (boot) volume
  346.  
  347. OSErr GetIndVolume(short index,
  348.                    short& vRefNum);
  349.     // Get the vRefNum of an indexed on-line volume
  350.  
  351. OSErr VolHasDesktopDB(short vRefNum,
  352.                       Boolean& hasDesktop);
  353.     // Check if a volume supports desktop DB calls
  354.  
  355. OSErr FindAppOnVolume(OSType sig,
  356.                       short vRefNum,
  357.                       FSSpec& thefile);
  358.     // Ask vol's desktop db for application
  359.  
  360. OSErr LaunchAppByFSSpec(const FSSpec& fileSpec,
  361.                         LaunchFlags launchControlFlags,
  362.                         ProcessSerialNumber& psn);
  363.     // Launch app given a fileSpec
  364.  
  365.  
  366. OSErr LaunchBySignature(OSType sig,            // Signature of app
  367.                         ProcessSerialNumber& psn,// Returns PSN of app
  368.                         FSSpec * fileSpec,    // Returns location of app (ignored if NULL)
  369.                         Boolean * launched,    // Returns true if I had to launch (NULL ok)
  370.                         Boolean allowLaunch,// OK to launch it if not running?
  371.                         LaunchFlags launchControlFlags// Launch control flags; see Process Mgr
  372.                         );
  373.     // Main routine. Find app, launching if need be
  374. #endif
  375.  
  376.  
  377.